﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Media;

namespace TfL
{
    public class LineCodes
    {

        private static readonly Dictionary<string, string> _codes = new Dictionary<string, string>()
                                                                        {
                                                                            {"Bakerloo", "B"},
                                                                            {"Central Line", "C"},
                                                                            {"District", "D"},
                                                                            {"Hammersmith & City", "H"},
                                                                            {"Jubilee", "J"},
                                                                            {"Metropolitan", "M"},
                                                                            {"Northern", "N"},
                                                                            {"Piccadilly", "P"},
                                                                            {"Victoria", "V"},
                                                                            {"Waterloo & City", "W"}
                                                                        };

        private static readonly Dictionary<string, System.Windows.Media.Color> _colors = new Dictionary<string, System.Windows.Media.Color>()
        {
            {"Bakerloo",Color.FromArgb(255,137,78,36)},
            {"Central Line",Color.FromArgb(255,220,36,31)},
            {"Circle Line",Color.FromArgb(255,255,206,0)},
            {"District",Color.FromArgb(255,0,114,41)},
            {"Hammersmith & City",Color.FromArgb(255,215,153,175)},
            {"Jubilee",Color.FromArgb(255,134,143,152)},
            {"Metropolitan",Color.FromArgb(255,117,16,86)},
            {"Northern",Color.FromArgb(255,0,0,0)},
            {"Piccadilly",Color.FromArgb(255,0,25,168)},
            {"Victoria",Color.FromArgb(255,0,160,226)},
            {"Waterloo & City",Color.FromArgb(255,118,208,189)},
            {"DLR",Color.FromArgb(255,0,175,173)},
            {"Overground",Color.FromArgb(255,232,106,16)}
        };

        public static Color  ToColor(string name)
        {
            if (_colors.ContainsKey(name))
            {
                return _colors[name];
            }

            var line =(from n in _colors.Keys
                        where n.Contains(name.Split(' ')[0])
                        select n).FirstOrDefault();
            return line == null ? System.Windows.Media.Colors.DarkGray : _colors[line];
                

            
        }

        public static string FromName(string line)
        {
            string code = string.Empty;
            if(_codes.ContainsKey(line))
            {
                code = _codes[line];
            }
            return code;
        }

        public static string[] Codes
        {
            get { return _codes.Values.ToArray(); }
        }

        public static string[] Names
        {
            get { return _codes.Keys.ToArray(); }
        }

        public static Color[] Colors
        {
            get { return _colors.Values.ToArray(); }
        }
    }
}
